//
//  LGTeamConsultSettingVC.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/28.
//  团队咨询设置

#import "LGTeamConsultSettingVC.h"

#import "LGLineTitleTipView.h"
#import "LGInputAlertView.h"
@interface LGTeamConsultSettingVC ()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *timeView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *priceView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *numberView;
@end

@implementation LGTeamConsultSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"团队咨询设置";
    [self.view addSubview:self.baseView];
    [self.baseView addSubview:self.timeView];
    [self.baseView addSubview:self.priceView];
//    [self.baseView addSubview:self.numberView];
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.timeView.content = [NSString stringWithFormat:@"%ld小时",[dataDic[@"duration"] integerValue]/3600];
}

-(void)setNumber:(NSString *)number{
    _number = number;
    self.numberView.content = [NSString stringWithFormat:@"%@ 条",number];
}


-(void)tableFooterViewTouchAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self.baseView];
    if(CGRectContainsPoint(self.numberView.frame, point)){
        __block NSInteger min = [self.dataDic[@"message_times_min"] integerValue];
        __block NSInteger max = [self.dataDic[@"message_times_max"] integerValue];
        __block NSString *placeHolder = [NSString stringWithFormat:@"请输入%ld-%ld之间的整数",min,max];
        LGInputAlertView *alertView = [[LGInputAlertView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H)];
        alertView.placeHolder = placeHolder;
        alertView.title = @"消息数量上限";
        alertView.unit = @"条";
        alertView.keyboardType = UIKeyboardTypeNumberPad;
        [self.view.window addSubview:alertView];
        alertView.groupNameFinished = ^(NSString * _Nonnull content) {
            if([content integerValue]<min || [content integerValue]>max){
                [TooltipView showMessage:placeHolder offset:0];
            }else{
                [RequestUtil withPOST:@"/doctor/my.teams/saveServiceNum" parameters:@{@"team_id":self.teamId,@"num":content} withSign:YES success:^(NSInteger code, NSString *message, id returnData) {
                    if(code == 200){
                        self.numberView.content = [NSString stringWithFormat:@"%@ 条",content];
                        [self.navigationController popViewControllerAnimated:YES];
                    }else{
                        [TooltipView showMessage:message offset:0];
                    }
                } error:^(NSError *error) {
                    [TooltipView showMessage:LGErrorMessage offset:0];
                }];
            }
        };
    }
}


-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), viewPix(100))];
        [_baseView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
        [_baseView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tableFooterViewTouchAction:)]];
    }
    return _baseView;
}

-(LGLineTitleTipView *)timeView{
    if(!_timeView){
        _timeView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, viewPix(12), Screen_W-viewPix(32), viewPix(34))];
        _timeView.lineView.hidden = YES;
        _timeView.title = @"咨询时间";
        _timeView.type = @"text";
        _timeView.content = @"48小时";
        [_timeView.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0));
        }];
    }
    return _timeView;
}

-(LGLineTitleTipView *)priceView{
    if(!_priceView){
        _priceView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.timeView.frame)+viewPix(12), Screen_W-viewPix(32), viewPix(34))];
        _priceView.lineView.hidden = YES;
        _priceView.title = @"咨询价格";
        _priceView.type = @"text";
        _priceView.content = @"服务包赠送";
        [_priceView.tipView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(0));
        }];
    }
    return _priceView;
}

-(LGLineTitleTipView *)numberView{
    if(!_numberView){
        _numberView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.priceView.frame)+viewPix(10), Screen_W-viewPix(32), viewPix(34))];
        _numberView.lineView.hidden = YES;
        _numberView.title = @"患者消息数量上限";
        _numberView.type = @"text";
    }
    return _numberView;
}




/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
